// Copyright (c) 2023 坚果派
// 公众号：nutpi
// 电话：17752170152
// 官网：https://www.nutpi.net/
// All rights reserved.

import 'package:flutter/material.dart';
import '../services/url_service.dart';
import '../services/phone_service.dart';

class AboutPage extends StatelessWidget {
  const AboutPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('关于我们'),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            const SizedBox(height: 20),
            const Icon(
              Icons.health_and_safety,
              size: 80,
              color: Colors.green,
            ),
            const SizedBox(height: 20),
            const Text(
              '健康助手',
              style: TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
              ),
            ),
            const SizedBox(height: 10),
            const Text(
              '版本 1.0.0',
              style: TextStyle(color: Colors.grey),
            ),
            const SizedBox(height: 30),
            const Divider(),
            const SizedBox(height: 20),
            _buildContactItem(
              icon: Icons.person,
              title: '作者',
              subtitle: '坚果派',
            ),
            _buildContactItem(
              icon: Icons.public,
              title: '公众号',
              subtitle: 'nutpi',
            ),
            _buildContactItem(
              icon: Icons.phone,
              title: '电话',
              subtitle: '17752170152',
              onTap: () async {
                // Use direct caller to make a phone call
                try {
                  await PhoneService.callNumber('17752170152');
                } catch (e) {
                  if (context.mounted) {
                    ScaffoldMessenger.of(context).showSnackBar(
                      const SnackBar(content: Text('无法拨打电话')),
                    );
                  }
                }
              },
            ),
            _buildContactItem(
              icon: Icons.language,
              title: '官网',
              subtitle: 'https://www.nutpi.net/',
              onTap: () async {
                try {
                  await UrlService.openUrl('https://www.nutpi.net/');
                } catch (e) {
                  if (context.mounted) {
                    ScaffoldMessenger.of(context).showSnackBar(
                      const SnackBar(content: Text('无法打开网站')),
                    );
                  }
                }
              },
            ),
            const SizedBox(height: 30),
            const Divider(),
            const SizedBox(height: 20),

            // Enhanced copyright section with card
            Card(
              elevation: 2,
              color: Colors.green.shade50,
              child: Padding(
                padding: const EdgeInsets.all(16.0),
                child: Column(
                  children: [
                    const Text(
                      '版权信息',
                      style: TextStyle(
                        fontSize: 18,
                        fontWeight: FontWeight.bold,
                        color: Colors.green,
                      ),
                    ),
                    const SizedBox(height: 12),
                    const Text(
                      '© 2023 坚果派. All rights reserved.',
                      style: TextStyle(fontWeight: FontWeight.bold),
                      textAlign: TextAlign.center,
                    ),
                    const SizedBox(height: 8),
                    const Text(
                      '作者：坚果派\n公众号：nutpi\n电话：17752170152\n官网：https://www.nutpi.net/',
                      textAlign: TextAlign.center,
                      style: TextStyle(height: 1.5),
                    ),
                  ],
                ),
              ),
            ),

            const SizedBox(height: 20),
            const Text(
              '本应用仅供学习和参考，所提供的健康信息不应被视为专业医疗建议。',
              style: TextStyle(fontSize: 12, color: Colors.grey),
              textAlign: TextAlign.center,
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildContactItem({
    required IconData icon,
    required String title,
    required String subtitle,
    VoidCallback? onTap,
  }) {
    return ListTile(
      leading: Icon(icon, color: Colors.green),
      title: Text(title),
      subtitle: Text(subtitle),
      onTap: onTap,
      trailing:
          onTap != null ? const Icon(Icons.arrow_forward_ios, size: 16) : null,
    );
  }
}
